# TileMngr class
# Handles the loading of TileDescriptors

import yaml

from crl_tile import TileDescriptor

TILE_DIRECTORY = "/mnt/sdcard/sl4a/scripts/drew/python3/cellrl/data/tiles/"

class TileMngr:
  instance = None
  
  @staticmethod
  def get():
    if TileMngr.instance == None:
      TileMngr.instance = TileMngr()
    return TileMnge.instance
  
  def __init__(self):
    self.tiles = {}
  
  def clearTiles(self):
    self.tiles = {}
  
  def loadTiles(self, fname):
    tmptiles = {}
    with open(TILE_DIRECTORY+fname, "r") as f:
      tmptiles = yaml.load(f)
    
    for key, value in tmptiles.items():
      self.tiles[key] = TileDescriptor(
        value["icoch"],
        value["icofg"],
        value["icobg"],
        value["name"],
        value["desc"],
        value["passable"],
        value["opendoor"],
        value["closedtile"],
        value["closeddoor"],
        value["opentile"])
